<html>
<body>

<b>
Calculator
</br>
</b>

<form action="calculator.php" method="post">
<input type="text" name="input" />
<input type="submit" value = "Calculate" />
</form> 

<b>
Result
</br>
</b>

<?php
$input = $_POST['input'];

$minusminus= '%--%';
$dividebyzero= '%/0%';
$expression= '%^(-)?\d+(\.\d+)?([+*\/-](-)?\d+(\.\d+)?)*$%';

if (preg_match($expression, $input) && !preg_match($minusminus, $input) && !preg_match($dividebyzero, $input))
{
	eval('$result = ' . $input . ';');
	$output = $input . " = " . $result;
		
}
else
{
	$output = $input . " is not a valid expression";
}
echo $output;
?> <br/>

</body>
</html>